home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / seekchar.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-04  |  1.6 KB  |  64 lines

  1. ;unsigned short  seek_char(strg,ch,start_pt);
  2. ;  unsigned char  *strg,ch,start_pt;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _seek_char
  10. _seek_char proc near
  11.     push bp            ;
  12.     mov  bp,sp        ;set up stack frame
  13.     push di            ;
  14.     push si            ;
  15.     mov  _error_code,1    ;1 = error occurred
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bp            ;else add 2 to BP
  19.     inc  bp            ;
  20. begin:    cmp  _memory_model,2    ;data near or far?
  21.     jb   L0            ;jump if near
  22.     les  di,dword ptr[bp+4] ; ES:DI pts to Strg
  23.     inc  bp            ;add 2 to BP since dword ptr
  24.     inc  bp            ;
  25.     jmp  short L1        ;
  26. L0:    mov  di,[bp+4]        ;NEAR case
  27.     mov  ax,ds        ;ES = DS
  28.     mov  es,ax        ;
  29. L1:    mov  dh,[bp+6]        ;DH holds the char sought
  30.     sub  cx,cx        ;counter
  31.     mov  cl,[bp+8]        ;start point
  32.     inc  cl            ;count from 1
  33.     mov  ax,cx        ;AX holds string position
  34.     dec  ax            ;adjust
  35.     cmp  cl,1        ;need to forward ptr?
  36.     je   L3            ;jump if not
  37. L2:    cmp  byte ptr es:[di],0    ;end of string?
  38.     je   L4            ;quit if so
  39.     inc  di            ;forward ptr for next time
  40.     loop L2            ;loop
  41.     dec  di            ;
  42. L3:    mov  dl,es:[di]        ;now start seeking the char
  43.     inc  ax            ;forward strg ptr
  44.     cmp  dl,dh        ;the search char?
  45.     je   L5            ;jump if found
  46.     cmp  dl,0        ;end of string?
  47.     je   L4            ;jump if so
  48.     inc  di            ;
  49.     jmp  short L3        ;go get next char
  50. L4:    sub  ax,ax        ;char not found, return zero
  51.     jmp  short L6        ;jump ahead
  52. L5:    dec  _error_code    ;0 = no error
  53. L6:    pop  si            ;
  54.     pop  di            ;
  55.     pop  bp            ;
  56.     dec  ax            ;count return value from 0
  57.     cmp  _memory_model,0    ;quit
  58.     jle  quit        ;
  59.     db   0CBh        ;RET far
  60. quit:    ret            ;RET near
  61. _seek_char ENDP
  62. _TEXT    ENDS
  63.     END
  64.